<template>
  <div class="editTransport">
    <el-form :model="form" :rules="rules" ref="ruleForm" label-width="120px">
      <el-form-item label="运输公司名称" prop="business_name">
        <el-input v-model="form.business_name" placeholder="输入运输公司名称"></el-input>
      </el-form-item>
      <el-form-item label="运输许可证号" prop="business_license">
        <el-input v-model="form.business_license" placeholder="输入运输许可证号"></el-input>
      </el-form-item>
      <el-form-item label="社会信用代码" prop="credit_code">
        <el-input v-model="form.credit_code" placeholder="输入社会信用代码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('ruleForm')">确定</el-button>
        <!-- <el-button>取消</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {editTransportCompany} from '@/api/set';
import {deepClone} from "@/utils/tool";
export default {
  name: "editTransport",
  props: {
    row: {
      default: {},
      type: Object
    }
  },
  data() {
    return {
      form: {
        business_name: "",
        business_license: "",
        credit_code: "",
      },
      rules: {
        business_name: [
          { required: true, message: "请输入运输公司名称", trigger: "blur" }
        ],
        business_license: [
          { required: true, message: "请输入运输许可证号", trigger: "blur" }
        ],
        credit_code: [
          { required: true, message: "请输入社会信用代码", trigger: "blur" }
        ],
      }
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      this.form = deepClone(this.row);
    },
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let result = await editTransportCompany(this.form);
            if(result.code == 200){
                this.$message.success(result.msg || '编辑成功');
                setTimeout(() => {
                    this.$emit('refresh');
                }, 500);
            }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.editTransport {
}
</style>
